
var express=require("express");
var morgan=require("morgan");
var compress=require("compression");
var bodyParser=require("body-parser");
var methodOverride=require("method-override");
var session=require("express-session");
var config=require("./config");
module.exports=function(){
	console.log("call express.....");
	var app=express();
	if(process.env.NODE_ENV==='development'){
		app.use(morgan('dev'));
	}
	else if(process.env.NODE_ENV==='production'){
		app.use(compress());
	}
	
	app.use(bodyParser.urlencoded({extended:true}));
	app.use(bodyParser.json());
	app.use(methodOverride());

	//加载session处理插件
	app.use(session({
		saveUninitialized:true,
		resave:true,
		secret:config.sessionSecret
	}));

	//指定ejs为模板引擎（控制器将使用res.render()来指定模板名称）
	app.set('views','./app/views');//模板文件的保存路径
	app.set('view engine','ejs');//指定模板引擎

	var route=require("../app/routes/index.server.route");
	route(app);
	require("../app/routes/users.server.route")(app);
	app.use(express.static('./public'));//加载静态文件服务的中间件
	return app;
}
